package com.jie.dao;

import com.jie.service.FileService;
import com.jie.show.FileInfo;
import com.jie.show.User;
import com.jie.util.R;
import com.sun.deploy.security.JarSignature;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;

@Component
public class FileDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    JdbcTemplate template;


    /**
     * 根据文件MD5查询文件上传记录
     *
     * @param md5
     * @return
     */
    public FileInfo getFileInfoByMD5(String md5) {
        try {
            return template.queryForObject("select * from t_chanson where md5 = ?", new BeanPropertyRowMapper<>(FileInfo.class), md5);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 保存文件上传记录
     *
     * @param info
     * @return
     */
    public boolean createFileInfo(FileInfo info) {
        return template.update("insert into t_chanson (name, url, path, size, type, md5, account) values (?, ?, ?, ?, ?, ?,?)", info.getName(), info.getUrl(), info.getPath(), info.getSize(), info.getType(), info.getMd5(),info.getAccount()) > 0;
    }
}
